package com.gc.business.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gc.common.utils.StringUtils;
import org.springframework.stereotype.Service;
import com.gc.business.mapper.KnowledgeBaseMapper;
import com.gc.business.domain.KnowledgeBase;
import com.gc.business.service.IKnowledgeBaseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;

/**
 * 知识库数据 服务层实现
 *
 * @author liujinteng
 * @date 2020-10-27
 */
@Slf4j
@Service
public class KnowledgeBaseServiceImpl extends ServiceImpl<KnowledgeBaseMapper, KnowledgeBase> implements IKnowledgeBaseService {

    @Override
    public List<KnowledgeBase> list(KnowledgeBase knowledgeBase) {
        LambdaQueryWrapper<KnowledgeBase> wrapper = new LambdaQueryWrapper<>();
        if (knowledgeBase != null) {
            if (StringUtils.isNotEmpty(knowledgeBase.getBaseId())) {
                wrapper.eq(KnowledgeBase::getBaseId, knowledgeBase.getBaseId());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getAttrId())) {
                wrapper.eq(KnowledgeBase::getAttrId, knowledgeBase.getAttrId());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getClassifyId())) {
                wrapper.eq(KnowledgeBase::getClassifyId, knowledgeBase.getClassifyId());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getBaseName())) {
                wrapper.like(KnowledgeBase::getBaseName, knowledgeBase.getBaseName());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getClassifyName())) {
                wrapper.like(KnowledgeBase::getClassifyName, knowledgeBase.getClassifyName());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getFormatType())) {
                wrapper.eq(KnowledgeBase::getFormatType, knowledgeBase.getFormatType());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getVideoUrl())) {
                wrapper.eq(KnowledgeBase::getVideoUrl, knowledgeBase.getVideoUrl());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getCoverImg())) {
                wrapper.eq(KnowledgeBase::getCoverImg, knowledgeBase.getCoverImg());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getArticleContent())) {
                wrapper.like(KnowledgeBase::getArticleContent, knowledgeBase.getArticleContent());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getCreateBy())) {
                wrapper.eq(KnowledgeBase::getCreateBy, knowledgeBase.getCreateBy());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getCreateTime())) {
                wrapper.eq(KnowledgeBase::getCreateTime, knowledgeBase.getCreateTime());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getUpdateBy())) {
                wrapper.eq(KnowledgeBase::getUpdateBy, knowledgeBase.getUpdateBy());
            }
            if (StringUtils.isNotEmpty(knowledgeBase.getUpdateTime())) {
                wrapper.eq(KnowledgeBase::getUpdateTime, knowledgeBase.getUpdateTime());
            }
        }
        return baseMapper.selectList(wrapper);
    }

}
